/**
 * @功能 ajax + callback 发起异步请求，并用callback处理
 * @param {string} url 
 * @param {string} params 
 * @param {object} headers 
 * @param {string} dataType 
 * @param {funciton} cb 
 */
function ajax_get_withCallback(url = '', params = '', headers = {}, dataType = 'JSON', cb) {
	const xhr = new XMLHttpRequest()
	xhr.onreadystatechange = function () {
		if (xhr.readyState === 4) {
			if (xhr.status === 200) {
				let data = xhr.responseText
				switch (dataType) {
					case 'JSON': {
						data = JSON.parse(data)
						break
					}
					case 'XML': {
						break
					}
					default: break
				}
				cb(data)
			} else {
				console.log(`请求出错，这是状态码：${xhr.status}`)
			}
		}
	}
	xhr.open('get', `${url}?${params}`)

	for (let key in headers) {
		xhr.setRequestHeader(key, headers[key])
	}
	xhr.send()
}